common = {
	initCatalogueMagePage: function () {
		// 绑定dom对象
		this.obj = {
			searchText: $('#searchText'),
			userNameInp: $('#userNameInp'),
		};
		// 声明全局变量
		this.vars = {
			selectTypeArr:[{val:'0',name:'全部'},{val:'1',name:'当前连接下级平台'},{val:'2',name:'下级平台所属的单一业户'}],
			areaCodeRole: {
				areaId: ''
			},
			pramsData: { //用户列表
				page: 1,
				size: 10,
				userName: ''
			},
			deleteId: { //删除
				id: ''
			},
			updateId: {
				id: ''
			}, //编辑id
			updateModelId: '', //修改用户id
			addUser: {}, //新增用户
			updateUserInfor: {}, //修改用户信息
			// zTree: {},
			zTree: {},
			powerParams: {
				user_id: '', //用户id
				area: '', //地区
				trans_type: '', //行业类别
				vehicle_id: '', //车辆
				// alarm_code: '', //报警类型
				role_id: '' //角色id
			},
			carParam: { //选择车辆
				userId: '', //用户id
				platformName: '', //平台模糊
				owersName: '', //企业模糊
				vehicleNo: '', //车牌号模糊
				areaId: '', //地区code
				state: '', //分配 未分配
				page: 1,
				size: 10
			},
			selectTypeArr:[{val:'1',name:'可用'},{val:'0',name:'不可用'}],//是否李可用下拉
			selectTypeArrRole:[],//所属角色下拉
			node: '', //选择dom树的节点
			chooseVehicleNo: [],//已选择的车牌
			currentPage: 1,//当前页
			setting: {
				view: {
					showIcon: false,
					showLine: false
				},
				check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			}
		};
		this.init();
		this.bindEvent();
	},
	init: function () {
		let that = this
		this.getTableList('/api/sysUser', this.vars.pramsData, '#manageTable', true, true);
		// this.getWarnTypeTree();
		jdSelect.JdSelectRadioInit('#d-select-duix', this.vars.selectTypeArr, (select) => {

		})

		//十分年月日单个
        $('#datetime_start').datePicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            hide: function (type) {
                that.vars.updateUserInfor.expirationDate = this.$input.val()
            }
        });

        $('#datetime_start_edit').datePicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            hide: function (type) {
                that.vars.addUser.expirationDate = this.$input.val()
            }
        });
	},
	bindEvent: function () {
		let self = this;
		$("#checkBtn").click(function () {
			let user = $("#userNameInp").val();
			self.vars.pramsData.userName = user;
			self.vars.pramsData.page = 1;
			self.getTableCutpge('/api/sysUser', self.vars.pramsData, '#manageTable')

		})
		$("#refreshBtn").click(function () {
			self.obj.userNameInp.val(' ');
			self.vars.pramsData.userName = '';
			self.getTableCutpge('/api/sysUser', self.vars.pramsData, '#manageTable')
		})
		//新增确定
		$("#sure").click(function () {
			let act = $("#addActivated .select-down-ul .active").attr('data-val');
			if(act !== undefined && act !== 'no'){
				var dataForm = $("#addUser").serializeArray();
				let key = '';
				if ($("#addUser").valid()) {
					for (let k of dataForm) {
						self.vars.addUser[k.name] = k.value;
					}
					let area = $("#manageAreaName").attr('data-id');
					self.vars.addUser.areaName = area;
					self.vars.addUser.activated = act;
					self.addNewAccount('/api/sysUser', self.vars.addUser, '#manageTable')
				}
			}else{
				JPop.alert("请选择账号是否可用!")
				return false
			}
			
		});
		//修改确定按钮
		$("#updateSure").click(function () {
			let actUpdate = $("#updateActivated .select-down-ul .active").attr('data-val');
			if(actUpdate !== undefined && actUpdate !== 'no'){
				var dataForm = $("#updateForm").serializeArray();
				let key = '';
				if ($("#updateForm").valid()) {
					for (let k of dataForm) {
						self.vars.updateUserInfor[k.name] = k.value;
					}
					//获取地区对应的字段code
					let area = $("#manageAreaNameUpdate").attr('data-id');
					self.vars.updateUserInfor.areaName = area;
					self.vars.updateUserInfor.id = self.vars.updateId.id;
					self.vars.updateUserInfor.activated = actUpdate;
					self.getUpdateUser('/api/sysUser', self.vars.updateUserInfor)
				}
			}else{
				JPop.alert("请选择账号是否可用!")
				return false
			}
		});
		//选择车辆车牌
		$("#chooseCarBox").click(function () {
			$("#carTable").show();
			self.getTableList('/api/sysUser/vehicle', self.vars.carParam, '#dialog_table', false, true);
			//加载选择车辆的下拉树
			self.diquSelceted('.qrm-main-car', "car");
		});
		//点击报警类型
		$("#selectimgdiv").click(() => {
			$(".alarm-tree").toggle();
		});
		//新增按钮
		$("#addAccountInf").click(function () {
			$("#userDialog").show();
			jdSelect.JdSelectRadioInit('#addActivated', self.vars.selectTypeArr, (select) => {
			})
			// jdSelect.setSelectRadio('#addActivated',this.vars.selectTypeArrRole,roleIdCode)
			self.validateForm("#addUser");
			self.diquSelceted('.qrm-main-add', "add")
		});
		//关闭 取消授权弹窗
		$('.power-cancel-close').click(function () {
			$("#carCard").val("");
			// self.getWarnTypeTree();
			$("#power").hide();
		});
		//选择车辆确定按钮
		$("#carSure").click(function () {
			//清空form表单
			$("#carAreaName").val('')
			$("#fp_dialog_search_platform_name").val('');
			$("#fp_dialog_search_platform_name").val('');
			$("#fp_dialog_search_owers_name").val('');
			$("#fp_dialog_search_vehicle_no").val('');
			$("#dialog_select_allcation").val('');
			self.vars.carParam.platformName = '';
			self.vars.carParam.owersName = '';
			self.vars.carParam.vehicleNo = '';
			self.vars.carParam.areaId = '';
			self.vars.carParam.state = '';
			self.vars.carParam.page = 1;
			//获取选中的行的信息
			var chooseCard = $('#dialog_table').bootstrapTable('getSelections');//获取选择行数据
			let cardCode = '';
			let carName = '';
			if (chooseCard !== null && chooseCard.length !== 0) {
				$.each(chooseCard, function (k, v) {
					cardCode += v.id + ',';
					carName += v.vehicleNo + ',';
				})
			}
			cardCode = (cardCode.substring(cardCode.length - 1) == ',') ? cardCode.substring(0, cardCode.length - 1) : cardCode;
			carName = (carName.substring(carName.length - 1) == ',') ? carName.substring(0, carName.length - 1) : carName;
			self.vars.powerParams.vehicle_id = cardCode;
			self.vars.chooseVehicleNo = carName.split(',');
			$("#carTable").hide();
			if (self.vars.chooseVehicleNo !== null && self.vars.chooseVehicleNo.length !== 0) {
				let VehicleNo = self.vars.chooseVehicleNo;
				let VehicleNoStr = '';
				$.each(VehicleNo, function (k, v) {
					VehicleNoStr += `<span class="vehicle">${v}</span>`;
				})
				$("#carCard").empty().append(VehicleNoStr);
			}
		});
		// 车辆弹框的查询
		$("#fp_dsearch").click(function () {
			let areacode = $("#carAreaName").attr("data-id");
			self.vars.carParam.platformName = $("#fp_dialog_search_platform_name").val();
			self.vars.carParam.owersName = $("#fp_dialog_search_owers_name").val();
			self.vars.carParam.vehicleNo = $("#fp_dialog_search_vehicle_no").val();
			self.vars.carParam.areaId = areacode;
			self.vars.carParam.state = $("#dialog_select_allcation").val();
			self.vars.carParam.page = 1;
			self.checkCar('/api/sysUser/vehicle', self.vars.carParam, '#dialog_table');
		});
		/**
		 * 重置
		 * */
		$("#fp_dreset").click(function () {
			//清空form表单
			$("#carAreaName").val('')
			$("#fp_dialog_search_platform_name").val('');
			$("#fp_dialog_search_platform_name").val('');
			$("#fp_dialog_search_owers_name").val('');
			$("#fp_dialog_search_vehicle_no").val('');
			$("#dialog_select_allcation").val('');
			self.vars.carParam.platformName = '';
			self.vars.carParam.owersName = '';
			self.vars.carParam.vehicleNo = '';
			self.vars.carParam.areaId = '';
			self.vars.carParam.state = '';
			self.vars.carParam.page = 1;
			self.getTableList('/api/sysUser/vehicle', self.vars.carParam, '#dialog_table', false, true);
		});
		// 授权确定按钮
		// $("#keepPowerSure").click(function () {
		// 	let checkboxStr = '';
		// 	let radioStr = '';
		// 	$.each($('.jdialog-row.checkbox .check-choose input:checkbox'), function () {
		// 		if (this.checked) {
		// 			let code = $(this).val();
		// 			checkboxStr += `${code},`;
		// 		}
		// 	});
		// 	$.each($('#sysType .check-choose input:radio'), function () {
		// 		if (this.checked) {
		// 			let radioValue = $(this).val();
		// 			radioStr += `${radioValue},`;
		// 		}
		// 	});
		// 	let surecheckboxStr = (checkboxStr.substring(checkboxStr.length - 1) == ',') ? checkboxStr.substring(0, checkboxStr.length - 1) : str;
		// 	let sureradioStr = (radioStr.substring(radioStr.length - 1) == ',') ? radioStr.substring(0, radioStr.length - 1) : str;
		// 	self.vars.powerParams.trans_type = surecheckboxStr;
		// 	self.vars.powerParams.alarm_code = sureradioStr;
		// 	let personType = $("#powerRule").val();
		// 	self.vars.powerParams.role_id = personType;
		// 	console.log(self.vars.powerParams, "授权")
		// 	self.getPersonPower('/api/sysUser/authorization', self.vars.powerParams);
		// })
		// 授权确定按钮
		$("#keepPowerSure").click(function () {

			/** 测试回显*/
			self.vars.powerParams.area = jdtree.getCheckIds();
			let checkboxStr = '';
			let radioStr = '';
			$.each($('.jdialog-row.checkbox .check-choose input:checkbox'), function () {
				if (this.checked) {
					let code = $(this).val();
					checkboxStr += `${code},`;
				}
			});
			$.each($('#sysType .check-choose input:radio'), function () {
				if (this.checked) {
					let radioValue = $(this).val();
					radioStr += `${radioValue},`;
				}
			});
			let surecheckboxStr = (checkboxStr.substring(checkboxStr.length - 1) == ',') ? checkboxStr.substring(0, checkboxStr.length - 1) : checkboxStr;
			let sureradioStr = (radioStr.substring(radioStr.length - 1) == ',') ? radioStr.substring(0, radioStr.length - 1) : radioStr;
			self.vars.powerParams.trans_type = surecheckboxStr;
			self.vars.powerParams.alarm_code = sureradioStr;
			// let personType = $("#powerRule").val();
			// self.vars.powerParams.role_id = personType;
			if (self.vars.powerParams.area.length > 0) {
				if (self.vars.powerParams.trans_type !== "") {
					self.getPersonPower('/api/sysUser/authorization', self.vars.powerParams);
				} else {
					JPop.alert("请选择行业类别!")
					return false
				}
			} else {
				JPop.alert("请选择地区!")
				return false
			}
		})
	},
	/**
	 * 
	 * 新增用户form表单
	 */
	validateForm: function (formDom) {
		//验证用户名
		$.validator.addMethod("checkUserName", function (value, element, params) {
			var checkUserName = /^\w{2,10}$/g;
			return this.optional(element) || (checkUserName.test(value));
		}, "请输入2-10位英文字母、数字或者下画线的用户名！");
		//验证姓名
		$.validator.addMethod("checkRealName", function (value, element, params) {
			var checkRealName = /^[\w\u4e00-\u9fa5]{2,10}/g;
			return this.optional(element) || (checkRealName.test(value));
		}, "请输入2-10位汉字、英文字母、数字或者下画线的姓名！");
		// 手机号码验证       
		jQuery.validator.addMethod("isMobile", function (value, element) {
			var length = value.length;
			var mobile = /^(13[0-9]{9})|(199[0-9]{8})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
			return this.optional(element) || (length == 11 && mobile.test(value));
		}, "请输入正确的手机号!");
		//验证邮箱
		$.validator.addMethod("checkEmail", function (value, element, params) {
			var checkEmail = /^[a-z0-9]+@([a-z0-9]+\.)+[a-z]{2,4}$/i;
			return this.optional(element) || (checkEmail.test(value));
		}, "请输入正确的邮箱！");
		$.validator.addMethod("checkPwd", function (value, element, params) {
			var checkPwd = /^\w{6,16}$/g;
			return this.optional(element) || (checkPwd.test(value));
		}, "请输入6-16位英文字母、数字或者下画线的密码！");
		var $addUser = $(formDom);
		$addUser.validate({
			rules: {
				userName: {
					required: true,
					minlength: 2,
					checkUserName: true
				},
				realName: {
					required: true,
					checkRealName: true,
					minlength: 2
				},
				email: {
					required: true,
					checkEmail: true
				},
				mobile: {
					required: true,
					isMobile: true
				},
				password: {
					required: true,
					// minlength: 5,
					checkPwd: true
				},
				realPassWord: {
					required: true,
					// minlength: 5,
					equalTo: "#addPassword"
				},
				manageAreaName: {
					required: true
				}

			},
			messages: {
				userName: {
					required: "用户名不能为空",
					minlength: "用户名最少两个字符"
				},
				realName: {
					required: "用户姓名不能为空",
					minlength: "用户姓名最少两个字符"
				},
				email: {
					required: "邮箱不能为空",
					email: "请输入正确的邮箱！",
				},
				mobile: {
					required: "手机号不能为空",
					mobile: "请输入正确的手机号！",

				},
				password: {
					required: "密码不能为空",
					// password: "密码长度不能小于6位",
					// rangelength: "请输入不少于6位的密码",
				},
				realPassWord: {
					required: "密码不能为空",
					// realPassWord: "密码不少于6位",
					// rangelength: "长度为2到10位！",
					equalTo: "两次密码不一致"
				},
				manageAreaName: {
					required: "所属地区不能为空"
				}
			}
		});
	},
	/**
	 * 请求地区数据
	 * */
	diquSelceted: function (dom, type) {
		var self = this;
		var mapurl = http + urls.diquSelceted;
		$.ajax({
			headers: {
				authorization: window.localStorage.getItem("auth_token") || ""
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			url: mapurl,
			type: "get",
			success: function (data) {
				data[0].code = 1;
				$.each(data[0].cityAreaVOS, function (i, dom) {
					data[0].cityAreaVOS[i].code = 2;
					$.each(data[0].cityAreaVOS[i].cityAreaVOS, function (j, dom) {
						data[0].cityAreaVOS[i].cityAreaVOS[j].code = 3;
					})
				})
				if (type == "add") {
					self.creatMainRidoAdd("qrm-main", dom, data, "cityAreaVOS", "code");
				} else if (type == "update") {
					self.creatMainRidoUpdate("qrm-main", dom, data, "cityAreaVOS", "code");
				} else if (type == "car") {
					self.creatMainRidoCar("qrm-main", dom, data, "cityAreaVOS", "code");
				}
			}
		});
	},
	/**
	 * 请求授权管理数据
	*/
	diquSelcetedPoweCheckbox: function (dom, dataMock) {
		var self = this;
		var mapurl = http + urls.diquSelceted;
		$.ajax({
			headers: {
				authorization: window.localStorage.getItem("auth_token") || ""
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			url: mapurl,
			data: dataMock,
			type: "get",
			success: function (data) {
				data[0].code = 1;
				$.each(data[0].cityAreaVOS, function (i, dom) {
					data[0].cityAreaVOS[i].code = 2;
					$.each(data[0].cityAreaVOS[i].cityAreaVOS, function (j, dom) {
						data[0].cityAreaVOS[i].cityAreaVOS[j].code = 3;
					})
				})
				self.creatMainCheckboxPower("qrm-main", dom, data, "cityAreaVOS", "code");
			}
		});
	},
	/**
	 * 选择车辆的选择地区
	 * */
	creatMainRidoCar: function (id, dom, attr, child, jibie) {
		$(id).html("");
		var sttrdiv = "";
		for (var i = 0; i < 3; i++) {
			sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
				"<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
				"</ul>" +
				"</div>"
		};
		$(dom).html(sttrdiv);
		var str = "";
		$("#carTable #qrm-border1").html("");
		var forTree = function (o) {
			for (var i = 0; i < o.length; i++) {
				var urlstr = "";
				try {
					urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
					str += urlstr;
					if (o[i][child] != null) {
						forTree(o[i][child]);
					}
					str += "</ul>";
				} catch (e) { }
			}
			return str;
		};
		$("#carTable #qrm-border1").html(forTree(attr));
	},
	/**
	 * 下拉框修改单选
	 * */
	creatMainRidoUpdate: function (id, dom, attr, child, jibie) {
		$(id).html("");
		var sttrdiv = "";
		for (var i = 0; i < 3; i++) {
			sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
				"<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
				"</ul>" +
				"</div>"
		};
		$(dom).html(sttrdiv);
		var str = "";
		$("#updateUser #qrm-border1").html("");
		var forTree = function (o) {
			for (var i = 0; i < o.length; i++) {
				var urlstr = "";
				try {
					urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
					str += urlstr;
					if (o[i][child] != null) {
						forTree(o[i][child]);
					}
					str += "</ul>";
				} catch (e) { }
			}
			return str;
		};
		$("#updateUser #qrm-border1").html(forTree(attr));
	},
	/**
 * 下拉框新增单选
 * */
	creatMainRidoAdd: function (id, dom, attr, child, jibie) {
		$(id).html("");
		var sttrdiv = "";
		for (var i = 0; i < 3; i++) {
			sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
				"<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
				"</ul>" +
				"</div>"
		};
		$(dom).html(sttrdiv);
		var str = "";
		$("#userDialog #qrm-border1").html("");
		var forTree = function (o) {
			for (var i = 0; i < o.length; i++) {
				var urlstr = "";
				try {
					urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
					str += urlstr;
					if (o[i][child] != null) {
						forTree(o[i][child]);
					}
					str += "</ul>";
				} catch (e) { }
			}
			return str;
		};
		$("#userDialog #qrm-border1").html(forTree(attr));
	},
	/**
	 * 下拉框复选授权
	 * */
	creatMainCheckboxPower: function (id, dom, attr, child, jibie) {
		$(id).html("");
		var sttrdiv = "";
		for (var i = 0; i < 3; i++) {
			sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
				"<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
				"</ul>" +
				"</div>"
		};
		$(dom).html(sttrdiv);
		var str = "";
		$("#power #qrm-border1").html("");
		var forTree = function (o) {
			for (var i = 0; i < o.length; i++) {
				var urlstr = "";
				try {
					urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
					str += urlstr;
					if (o[i][child] != null) {
						forTree(o[i][child]);
					}
					str += "</ul>";
				} catch (e) { }
			}
			return str;
		};
		$("#power #qrm-border1").html(forTree(attr));
	},
	/**
	 * 下拉框单选
	 * */
	creatMainCheckbox: function (id, dom, attr, child, jibie) {
		$(id).html("");
		var sttrdiv = "";
		for (var i = 0; i < 3; i++) {
			sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
				"<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
				"</ul>" +
				"</div>"
		};
		$(dom).html(sttrdiv);
		var str = "";
		$("#qrm-border1").html("");
		var forTree = function (o) {
			for (var i = 0; i < o.length; i++) {
				var urlstr = "";
				try {
					urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
					str += urlstr;
					if (o[i][child] != null) {
						forTree(o[i][child]);
					}
					str += "</ul>";
				} catch (e) { }
			}
			return str;
		};
		$("#qrm-border1").html(forTree(attr));
	},
	tableEvent: function (url, dom, tableMock, columnsData, paramMock, totalpage, showColumns, paginationShow) {
		let cutPage = paramMock.page;
		var self = this;
		$(dom).bootstrapTable({
			method: 'get',
			cache: false,
			height: 420,
			pagination: paginationShow,
			pageSize: 10,
			//			pageNumber: self.vars.pramsData.page,
			pageNumber: cutPage,
			showColumns: showColumns,
			striped: true,
			columns: columnsData,
			sidePagination: 'server', // client or server
			totalRows: totalpage,
			data: tableMock,
			onPageChange: function (size, number) {
				self.vars.currentPage = number;
				if (dom === "#manageTable") {
					self.vars.pramsData.page = self.vars.currentPage;
					self.getTableCutpge(url, self.vars.pramsData, dom)
				} else if (dom === "#dialog_table") {
					self.vars.carParam.page = self.vars.currentPage;
					self.getTableCutpge(url, self.vars.carParam, dom)
				}

			},
			formatNoMatches: function () {
				return '无符合条件的记录';
			}
		});
	},
	creatTable: function (url, dom, dataMock, paramMock, totalpage, showColumns, paginationShow) {
		var self = this;
		var columnsOne = [{
			field: 'no',
			title: '序号',
			align: 'center',
			formatter: function (value, row, index) {
				return index + 1;
			}
		},
		{
			field: 'manageAreaName',
			title: '所属地区',
			visible: true
		},
		{
			field: 'userName',
			title: '用户名',
			visible: true
		},
		{
			field: 'realName',
			title: '姓名',
			visible: true
		},
		{
			field: 'mobile',
			title: '电话',
			visible: true
		},
		{
			field: 'email',
			title: '邮箱',
			visible: true
		},
		{
			field: 'activated',
			title: '账户是否可用',
			visible: true
		},
		{
			field: 'caozuo',
			title: '操作',
			formatter: self.operateFormatter,
			events: window.operateEvents = {
				'click .ran_xq': function (e, value, row, index) {
					self.update(e, value, row, index)
				},
				'click .dele-row': function (e, value, row, index) {
					self.delate(e, value, row, index);
				},
				'click .give_power': function (e, value, row, index) {
					self.givePower(e, value, row, index);
					// self.getWarnTypeTree(row.areaName)
				}
			}
		}
		];
		var columnCar = [
			{
				field: 'checked',
				checkbox: true,
				width: "60"
			},
			{
				field: 'no',
				title: '序号',
				align: 'center',
				formatter: function (value, row, index) {
					return index + 1;
				}
			},

			{
				field: "vehicleNo",
				title: "车牌号码"
			},
			{
				field: "state",
				title: "分配状态"
			},
			{
				field: "areaName",
				title: "地区"
			},
			{
				field: "platformName",
				title: "运营商平台"
			},
			{
				field: "owersName",
				title: "企业"
			}
		];
		let columnsData = '';
		if (dom === "#manageTable") {
			columnsData = columnsOne;
		} else if (dom === "#dialog_table") {
			columnsData = columnCar;
		}
		self.tableEvent(url, dom, tableMock, columnsData, paramMock, totalpage, showColumns, paginationShow);
	},
	/**
	 * 初始化地区
	 * */
	setCheck() {
		this.vars.zTree = $.fn.zTree.getZTreeObj("treeDemo");
		this.vars.zTree.setting.check.chkboxType = {
			Y: "s",
			N: "s"
		};
	},
	/**
	 * 请求记录车辆详情接口数据
	 * */
	getTableList(url, pramsData, dom, showColumns, paginationShow) {
		$("#jid_loading").show()
		let self = this;
		jrequest.get(url, pramsData).then(res => {
			if (dom == "#manageTable") {
				res.data.forEach(item => {
					item.activated = item.activated == 0 ? '不可用' : '可用'
				})
			} else if (dom == "#dialog_table") {
				res.data.forEach(item => {
					item.state = item.state == 1 ? '已分配' : '未分配'
				})
			}
			let recordMock = [];
			let totalpage = '';
			tableMock = res.data;
			totalpage = res.total;

			this.creatTable(url, dom, tableMock, pramsData, totalpage, showColumns, paginationShow);

			$("#jid_loading").hide()
		})
	},
	/**
	 * 表格操作按钮
	 * */
	operateFormatter: function () {
		return [
			'<button id="table_get" class="give_power">授权</button>&nbsp&nbsp',
			'<button id="table_edit" class="ran_xq">修改</button>&nbsp&nbsp',
			'<button id="table_del" class="dele-row">删除</button>'
		].join('');
	},
	/**
	 * 删除功能
	 * */
	delate: function (e, value, row, index) {
		let self = this;
		// Jdialog.confirm({ message: "是否删除?" }).on(function (e) {
		// 	if (e) {
		// 		jrequest.delete(`/api/sysUser/${row.id}`, {}).then(res => {
		// 			self.getTableCutpge('/api/sysUser', self.vars.pramsData, '#manageTable')
		// 		})
		// 	}
		// });

		JPop.dialogDel({msg:"是否删除?",operate:true}).on(success => {
            if (success) {
                jrequest.delete(`/api/sysUser/${row.id}`, {}).then(res => {
					self.getTableCutpge('/api/sysUser', self.vars.pramsData, '#manageTable')
				})
            }
        })

	},
	/**
	 * 修改功能
	 * */
	update: function (e, value, row, index) {
		let self = this;
		let update = row.id;
		this.vars.updateId.id = update;
		jrequest.get('/api/sysUser/' + this.vars.updateId.id).then(res => {
			let datadMock = [];
			let totalpage = '';
			$("#updateUser").show();
			// 调用自定义的下拉框
			jdSelect.JdSelectRadioInit('#updateActivated', this.vars.selectTypeArr, (select) => {
			})
			datadMock = res.data;
			$("#userName").val(datadMock.userName);
			$("#realName").val(datadMock.realName);
			$("#email").val(datadMock.email);
			$("#mobile").val(datadMock.mobile);
			$("#d_input_starttime_edit").val(datadMock.expirationDate);
			// if (datadMock.activated === true) {
			// 	datadMock.activated = 1;
			// } else {
			// 	datadMock.activated = 0;
			// }
			// $("#updateActivated").val(datadMock.activated);
			jdSelect.setSelectRadio('#updateActivated',this.vars.selectTypeArr,datadMock.activated)
			$("#manageAreaNameUpdate").attr('data-id', datadMock.areaName);
			$("#manageAreaNameUpdate").val(datadMock.manageAreaName.replace(/,/g, '/'));
			self.diquSelceted('.qrm-main-update', "update")
			self.validateForm("#updateForm")
		})
	},
	/**
	 * 新增用户 重新获取全部用户g
	 * */
	addNewAccount: function (url, newAccData, dom) {
		let self = this;
		jrequest.post(url, newAccData).then(res => {
			let { data: { code } } = res;
			let { data: { msg } } = res;

			if (code == "-1") {
				
			} else if (code == "0") {
				$("#addUser")[0].reset();
				$("#userDialog").hide();
				
	            self.vars.pramsData.page = 1;
				self.obj.userNameInp.val(' ');
				self.vars.pramsData.userName = '';
				self.getTableCutpge('/api/sysUser', self.vars.pramsData, '#manageTable')
			}
		})
	},
	/**
	 * 修改用户
	 * */
	getUpdateUser: function (url, updateUserMock) {
		let self = this;
		jrequest.put(url, updateUserMock).then(res => {
			$("#updateForm")[0].reset();
			$("#updateUser").hide();
			self.vars.pramsData.page = 1;
			self.obj.userNameInp.val(' ');
			self.vars.pramsData.userName = '';
			self.getTableCutpge('/api/sysUser', self.vars.pramsData, '#manageTable')
		})
	},
	/**
	 * 更新数据
	 * */
	getTableCutpge(url, pramsData, dom) {

		let paramDataMock = pramsData;
		let self = this;
		jrequest.get(url, pramsData).then(res => {
			$(dom).bootstrapTable('destroy');
			if (dom == "#manageTable") {
				res.data.forEach(item => {
					item.activated = item.activated == 0 ? '不可用' : '可用'
				})
			} else if (dom == "#dialog_table") {
				res.data.forEach(item => {
					item.state = item.state == 1 ? '已分配' : '未分配'
				})
			}
			let recordMock = [];
			let totalpage = '';
			tableMock = res.data;
			totalpage = res.total;
			if (dom == "#manageTable") {
				this.creatTable(url, dom, tableMock, pramsData, totalpage, true, true);
				//				(url, dom, dataMock, paramMock ,totalpage, showColumns, paginationShow)
			} else if (dom == "#dialog_table") {
				this.creatTable(url, dom, tableMock, pramsData, totalpage, false, true);
			}

		})
	},
	/**
	 * 授权
	 * */
	givePower(e, value, row, index) {
		let self = this;
		let id = row.id;
		self.vars.updateId.id = row.id;
		self.vars.powerParams.user_id = row.id;
		self.vars.carParam.userId = row.id;
		self.vars.areaCodeRole.areaId = row.areaName;
		jrequest.get("/api/assessMent/selectByAreaVo", {areaId:row.areaName}).then(res => {
			let menu = res.data
			let a = (data) => {
				data.forEach(item => {
					item.code = item.id
					delete item.id
					item.disabled = false
					item.isOpened = true
					item.name = item.name
					// delete item.mangerName
					if (item.cityAreaVOS && item.cityAreaVOS.length > 0) {
						item.hasChild = true
						item.child = item.cityAreaVOS
						delete item.cityAreaVOS
						a(item.child)
					} else {
						item.hasChild = false
					}
				})
			}
			a(menu)
			jdtree.init(menu)
			jrequest.get(`/api/sysUser/authorization/${id}`, {}).then(res => {
				$("#power").show();
				let roleIdCode = res.data.roleId;
				self.getRolesSeleclt(self.vars.areaCodeRole, roleIdCode);

				let areaIdStr = res.data.areaIds;
				jdtree.setChecked(areaIdStr);
				let rule = res.data.alarmType;
				if (rule == 1) {
					$("#mind").attr("checked", "checked");
				} else {
					$("#drivingSafe").attr("checked", "checked");
				}
				// 行业类别
				let type = (res.data.transTypes).split(',');
				type.map((item, index) => {
					if (item == 1) {
						$("#custormCar").attr("checked", "checked");
					} else if (item == 2) {
						$("#tourCar").attr("checked", "checked");
					} else {
						$("#dangerCar").attr("checked", "checked");
					}
				})

				//已选择的车辆
				let haveChooseCar = res.data.vehicleIds;
				let haveChooseNumber = res.data.vehicleNos;
				if (haveChooseNumber !== "" && haveChooseNumber !== null) {
					let carNum = haveChooseNumber.split(';');
					let VehicleNoStr = '';
					$.each(carNum, function (k, v) {

						VehicleNoStr += `<span class="vehicle">${v}</span>`;
					})
					$("#carCard").empty().append(VehicleNoStr);
				}
				self.diquSelcetedPoweCheckbox('.qrm-main-power', self.vars.areaCodeRole);
			})
		})
		
	},

	/**
	 * 获取报警类型下拉树数据
	 * 
	 * */
	// 弹框中的菜单权限tree
	getWarnTypeTree: function (areaId) {
		jrequest.get("/api/assessMent/selectByAreaVo", {areaId:areaId}).then(res => {
			let menu = res.data
			let a = (data) => {
				data.forEach(item => {
					item.code = item.id
					delete item.id
					item.disabled = false
					item.isOpened = true
					item.name = item.name
					// delete item.mangerName
					if (item.cityAreaVOS && item.cityAreaVOS.length > 0) {
						item.hasChild = true
						item.child = item.cityAreaVOS
						delete item.cityAreaVOS
						a(item.child)
					} else {
						item.hasChild = false
					}
				})
			}
			a(menu)
			jdtree.init(menu)
		})
	},
	// getWarnTypeTree: function () {
	// 	let self = this;
	// 	jrequest.get("/api/assessMent/selectListByArea", {}).then(res => {
	// 		console.log(res, "rrrrrrrrrrrrrrrrrrrrrrrrrrr")
	// 		res.data.forEach(item => {
	// 			if (!item.parentId) item.open = true
	// 			item.id = item.id
	// 			item.pId = item.parentId
	// 		})
	// 		console.log(res.data)
	// 		let that = this
	// 		$.fn.zTree.init($("#treeDemo"), {
	// 			view: {
	// 				showIcon: false,
	// 				showLine: false
	// 			},
	// 			check: {
	// 				enable: true
	// 			},
	// 			data: {
	// 				simpleData: {
	// 					enable: true
	// 				}
	// 			},
	// 			callback: {
	// 				onCheck: (e, treeId, treeNode) => {
	// 					console.log(e, treeId, treeNode, "授权中的地区")
	// 					self.vars.nodes = self.vars.zTree.getChangeCheckedNodes();
	// 					// console.log(nodes)
	// 					let str = '';
	// 					let code = '';
	// 					self.vars.nodes.forEach(item => {
	// 						let mangerName = '';
	// 						mangerName = item.mangerName.replace(/,/g, "/");
	// 						str += `${mangerName},`;
	// 						code += `${item.id},`;
	// 					})
	// 					str = (str.substring(str.length - 1) == ',') ? str.substring(0, str.length - 1) : str;
	// 					console.log(str)
	// 					code = (code.substring(code.length - 1) == ',') ? code.substring(0, code.length - 1) : code;
	// 					$("#alarmvar").text(str);
	// 					// $("#alarmvar").val(str);
	// 					self.vars.powerParams.area = code;
	// 					console.log(code, "所属地区code")
	// 					console.log(str, "所属地区str")
	// 					console.log(self.vars.powerParams, "报警类型")
	// 				}
	// 			}
	// 		}, res.data);
	// 		self.setCheck();
	// 	})
	// },
	/**
	 * 获取授权--角色管理
	 * */
	getRolesSeleclt: function (pramsData, roleIdCode) {
		let self = this;
		jrequest.get('/api/role/list', pramsData).then(res => {
			let {
				data
			} = res;
			let roleobg = {val:'',name:''};
			// self.vars.selectTypeArrRole=[{val:'no',name:'请选择'}];
			if (data !== null && data.length !== 0){
				data.map((item,index)=>{
					roleobg = {val:item.id,name:item.nickName};
					self.vars.selectTypeArrRole.push(roleobg)
				})
				jdSelect.JdSelectRadioInit('#powerRule', self.vars.selectTypeArrRole, (select) => {
					self.vars.powerParams.role_id = select.val
				})
				if(roleIdCode !== null ){
					jdSelect.setSelectRadio('#powerRule',self.vars.selectTypeArrRole,roleIdCode)
				}else{
					// jdSelect.setSelectRadio('#powerRule',self.vars.selectTypeArrRole,"no")
				}
			} else {
				$("#powerRule").html("<p style='color:#868686;margin-left:10px;'>暂无角色</p>")
			}
			
			// jdSelect.setSelectRadio('#powerRule',this.vars.selectTypeArrRole,roleIdCode)
			// let str = '';
			// let allStr = '';
			// if (data !== null && data.length !== 0)
			// 	$.each(data, function (k, v) {
			// 		console.log(k, v)
			// 		str += `<option value=${v.id}>${v.nickName}</option>`
			// 	})
			// allStr = `<option value="no">请选择</option>${str}`;
			// $("#powerRule").empty().append(allStr);
			// if (roleIdCode !== null && roleIdCode !== undefined) {
			// 	$("#powerRule").val(roleIdCode);
			// }
		})
	},
	/**
	 * 选择车辆---查询功能
	 * */
	checkCar: function (url, pramsData, dom) {
		let self = this;
		jrequest.get(url, pramsData).then(res => {
			$("#carAreaName").val('')
			$("#fp_dialog_search_platform_name").val('');
			$("#fp_dialog_search_platform_name").val('');
			$("#fp_dialog_search_owers_name").val('');
			$("#fp_dialog_search_vehicle_no").val('');
			$("#dialog_select_allcation").val('');
			self.vars.carParam.platformName = '';
			self.vars.carParam.owersName = '';
			self.vars.carParam.vehicleNo = '';
			self.vars.carParam.areaId = '';
			self.vars.carParam.state = '';
			self.vars.carParam.page = 1;
			$("#dialog_table").bootstrapTable("destroy");
			//  	    self.getTableList(url, pramsData, dom, false, true) 
			let dataMock = res.data;
			let totalMock = res.total;
			self.creatTable(url, dom, dataMock, pramsData, totalpage, false, true)
		})
	},
	/**
	 * 授权
	 * */
	getPersonPower(url, pramsData) {
		jrequest.post(url, pramsData).then(res => {
			$("#power").hide();
		})
	},
	/**
	 * 授权窗口--关闭
	 */
	closePowerDialog() {
		let self = this;
		$("#carCard").empty();
		// self.getWarnTypeTree();
		$("#alarmvar").text("");
		$("#power").hide();
	}
}

$(function () {
	common.initCatalogueMagePage();
	// yjhhAlert("测试");
	// yjhhConform("测试",fuc)

});

function closeDialog() {
	var validator = $("#addUser").validate();
	validator.resetForm();
	$("#userDialog").hide();
}

function closeDialogUpdate() {
	var validator = $("#updateForm").validate();
	validator.resetForm();
	$("#updateUser").hide()
}

function closeRuleDialog() {
	$("#dialog_rule_allocation").hide();
}

function closeCarDialog() {
	$("#carTable").hide();
}